<?php
include_once '../action/cutiPribadiController.php';
include 'z_header.php';
if(!isset($_SESSION['nip'])){
    header('location:login.php');
}
if(isset($_GET['view'])){   
?>
<div class="container-fluid">  
    <div class="row-fluid">
<!-- AWAL TABEL LIHAT CUTI PRIBADI-->
<table class="table table-striped table-bordered">  
    <fieldset>  
         <legend><div class="pull-left">Daftar Pengajuan Cuti Pribadi</div>
                 <div class="pull-right"><a href="cuti.pribadi.php?rekam" class="btn btn-primary">Rekam Pengajuan Cuti</a></div>
         </legend>  
        <thead>  
          <tr>    
            <th width="125">Jenis Cuti</th>
            <th width="200">Tgl Cuti</th>
            <th width="200">Durasi Cuti</th> 
            <th width="200">Penanggung Jawab</th>  
            <th width="500">Catatan Pengajuan</th> 
            <th width="150">Cetak Surat</th>
            <th width="400">Aksi</th>
          </tr>  
        </thead>  
        <tbody> 
            <?php if($daftarpribadi!=NULL){
                foreach($daftarpribadi as $cutiku){?>
            <tr>
            <td><?php echo $cutiku->id_cuti.'<br>'.$cutiku->kategori_cuti; ?></td> 
            <td><?php echo $cutiku->tanggal_awal.' s/d'.'<br>'.$cutiku->tanggal_akhir; ?></td>  
            <td><?php echo $cutiku->durasi_cuti; ?></td> 
            <td><?php echo $cutiku->nip_pengganti.'<br>'.$cutiku->nama_pengganti; ?></td>
            <td><?php echo $cutiku->catatan_pengaju; ?></td>
            <td><a href="?cetak&id=<?php echo $cutiku->id_cuti;?>" <button class="btn"><i class="icon-print"></i>Cetak</button></a></td>
            
                <?php if($cutiku->status=="DIREKAM" OR ($_SESSION['pejabat']!='T' AND $cutiku->status=="DISETUJUI ATASAN/KASI")){ ?>
            <td>
                    <a href="?ubah&id=<?php echo $cutiku->id_cuti; ?>" <button class="btn btn-warning"><i class="icon-edit" align="center" ></i> Ubah</button></a>
                    <a href="?hapus&id=<?php echo $cutiku->id_cuti;?>" data-confirm="Anda Yakin Akan menghapus cuti <?php echo $cutiku->kategori_cuti; ?> tanggal  <?php echo $cutiku->tanggal_awal.' s/d '.$cutiku->tanggal_akhir; ?> ?" <button class="btn btn-danger"><i class="icon-remove"></i>Hapus</button></a>
            </td>
                <?php }else{
                    echo '<td><strong>'.$cutiku->status.'</strong></td>'; 
                    } ?>
            </tr>
                <?php }
                }else{ ?>
                    <td>Kosong</td>
                    <td>Kosong</td>
                    <td>Kosong</td>
                    <td>Kosong</td>
                    <td>-</td>
                    <td>-</td>
              <?php  } ?>
        </tbody>  
        </fieldset>
      </table>
<?php }

//AWAL HALAMAN REKAM CUTI
elseif(isset($_GET['rekam'])){ ?>
<div class="container">  
<div class="row">
    <div class="span8 offset2 accordion-group">
        <div class="span7">
            <form class="form-horizontal" method="post" action="" enctype="multipart/form-data">  
                <fieldset>  
                    <legend>&nbsp;Rekam Pengajuan Cuti Peribadi</legend>  
                    <?php
                    if(isset($error_hak)){
                        echo '<div class="alert alert-error" id="alert">'.$error_hak.'
                              <button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
                    }
                    if(isset($error_status)){
                        echo '<div class="alert alert-error" id="alert">'.$error_status.'
                              <button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
                    }
                    if(isset($error_durasi)){
                        echo '<div class="alert alert-error" id="alert">'.$error_durasi.'
                              <button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
                    }
                    ?>
                    <div class="control-group">  
                        <label class="control-label" for="kat_cuti">Kategori Cuti</label>  
                            <div class="controls">  
                                <select name="kat_cuti" class="input-large" id="kat_cuti"">
                                    <option value="0">--Pilih Kategori Cuti--</option>
                                <?php
                                foreach($kat as $kategori){
                                    echo "<option value=\"".$kategori->id_kategori."\">".$kategori->nm_kategori."</option>";
                                }
                                ?>      
                                </select>
                            </div>

                    </div>

                    <div class="control-group">  
                          <label class="control-label" for="tgl_awal">Tanggal Awal</label>  
                              <div class="controls">  
                                  <input type="text" class="input-medium" name="tgl_awal" id="tgl_awal">    
                              </div>  
                    </div>

                    <div class="control-group">  
                        <label class="control-label" for="tgl_akhir">Tanggal Akhir</label>  
                            <div class="controls">  
                                <input type="text" class="input-medium" name="tgl_akhir" id="tgl_akhir">
                            </div>  
                    </div>

                    <div class="control-group" id="penanggungjawab">  
                        <label class="control-label" for="nip_pengganti">Penanggungjawab Pekerjaan</label>  
                            <div class="controls">  
                                <select name="nip_pengganti" class="input-xlarge" id="nip_pengganti">
                                    <option value="0">--Pilih Pengganti--</option>
                                <?php
                                foreach($rekan as $rekanbagian){
                                    echo "<option value=\"".$rekanbagian->nip."\">".$rekanbagian->nama_pegawai."</option>";
                                }
                                ?>              
                                    </select>
                            </div>  
                    </div>

                     <div class="control-group">  
                        <label class="control-label" for="almt_cuti">Alamat Selama Cuti</label>  
                            <div class="controls">  
                                <textarea row="3" name="almt_cuti" class="input-xlarge" id="almt_cuti"></textarea>
                            </div>  
                    </div>

                    <div class="control-group">  
                        <label class="control-label" for="catatan_pengaju">Catatan pengajuan</label>  
                            <div class="controls">  
                                <textarea row="3" name="catatan_pengaju" class="input-xlarge" id="catatan_pengaju"></textarea>
                            </div>  
                    </div>

                    <div class="control-group" id="lampiran">  
                        <label class="control-label" for="file_cuti">Upload Surat Bukti</label>  
                            <div class="controls">  
                                <input type="file" class="input-medium" title="Pilih" name="file_cuti" id="file_cuti" data-bfi-disabled>
                            </div>  
                    </div>
                    <div class="form-actions">
                        <a href="cuti.pribadi.php?view" class="btn">Batal</a>
                        <button type="submit" class="btn btn-primary" name="simpan_rekamcuti">Simpan</button>  
                    </div>  
                </fieldset>  
            </form> 
        </div>
    </div>
<?php include_once 'z_footer.php';?>
<?php }

//AWAL UBAH CUTI
elseif(isset($_GET['ubah'])){
?>
<div class="container">  
    <div class="row">
        <div class="span8 offset2 accordion-group">
            <div class="span7">
                <form class="form-horizontal" method="post" action="" enctype="multipart/form-data">  
                        <fieldset>  
                            <legend>Ubah Pengajuan Cuti Peribadi</legend>  

                            <?php if($cutiedit!=NULL){
                                    foreach($cutiedit as $cutinya){?>
                            <input type="hidden" name="id_cuti"value="<?php $cutinya->id_cuti; ?>"> 
                            <div class="control-group">  
                                <label class="control-label" for="kat_cuti">Kategori Cuti</label>  
                                    <div class="controls">  
                                        <select name="kat_cuti" class="input-large" disabled id="kat_cuti"">
                                        <?php foreach($kat as $kategori){
                                            if($cutinya->kategori_cuti==$kategori->id_kategori){
                                                 echo "<option value=\"".$kategori->id_kategori."\" selected>".$kategori->nm_kategori."</option>";
                                            }else{
                                                echo "<option value=\"".$kategori->id_kategori."\">".$kategori->nm_kategori."</option>";
                                            }
                                        }
                                        ?>       
                                        </select>
                                    </div>

                            </div> 

                            <div class="control-group">  
                                  <label class="control-label" for="tgl_awal">Tanggal Awal</label>  
                                      <div class="controls">   
                                          <input type="text" class="input-medium" name="tgl_awal" id="tgl_awal" value="<?php echo $cutinya->tanggal_awal; ?>">    
                                      </div>  
                            </div>

                            <div class="control-group">  
                                <label class="control-label" for="tgl_akhir">Tanggal Akhir</label>  
                                    <div class="controls">  
                                        <input type="text" class="input-medium" name="tgl_akhir" id="tgl_akhir" value="<?php echo $cutinya->tanggal_akhir; ?>">
                                    </div>  
                            </div> 

                            <div class="control-group">  
                                <label class="control-label" for="nip_pengganti">Penanggungjawab Pekerjaan</label>  
                                    <div class="controls">  
                                        <select name="nip_pengganti" class="input-xlarge" >
                                        <?php
                                        var_dump($rekan);
                                        foreach($rekan as $rekanbagian){
                                            if($rekanbagian->nip==$cutinya->nip_penanggung){
                                                echo "<option value=\"".$rekanbagian->nip."\" selected>".$rekanbagian->nama_pegawai."</option>";
                                            }else{
                                                echo "<option value=\"".$rekanbagian->nip."\">".$rekanbagian->nama_pegawai."</option>";
                                            }
                                        }
                                        ?>               
                                            </select>
                                    </div>  
                            </div> 

                             <div class="control-group">  
                                <label class="control-label" for="almt_cuti">Alamat Selama Cuti</label>  
                                    <div class="controls">  
                                        <textarea row="3" name="almt_cuti" class="input-xlarge" id="almt_cuti"><?php echo $cutinya->alamat_cuti;?></textarea>
                                    </div>  
                            </div>

                            <div class="control-group">  
                                <label class="control-label" for="catatan_pengaju">Catatan pengajuan</label>  
                                    <div class="controls">  
                                        <textarea row="3" name="catatan_pengaju" class="input-xlarge" id="catatan_pengaju"><?php echo $cutinya->catatan_pengaju;?></textarea>
                                    </div>  
                            </div>

                            <div class="control-group">  
                                <label class="control-label" for="file_cuti">Upload Surat Bukti</label>  
                                    <div class="controls">  
                                        <input type="file" class="input-medium" title="Pilih" name="file_cuti" id="file_cuti" data-bfi-disabled>
                                    </div>  
                            </div>
                            <div class="form-actions"> 
                                <a href="cuti.pribadi.php?view" class="btn">Batal</a>
                                <button type="submit" class="btn btn-primary" name="simpan_ubahcuti">Simpan</button>  
                            </div> 
                                    <?php }
                            } ?>
                        </fieldset>  
                    </form> 
            </div>
<?php } ?>
<!--AKHIR FORM UBAH CUTI-->

<script type="text/javascript">
$(document).ready(function(){
                $( "#tgl_awal" ).datepicker();
                $( "#tgl_akhir" ).datepicker();
                 $('a[data-confirm]').click(function(ev) {
                                var href = $(this).attr('href');

                                if (!$('#dataConfirmModal').length) {
                                        $('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="dataConfirmLabel">Konfirmasi Peghapusan</h3></div><div class="modal-body"></div><div class="modal-footer"><button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Batal</button><a class="btn btn-danger" id="dataConfirmOK">Ya</a></div></div>');
                                }
                                $('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
                                $('#dataConfirmOK').attr('href', href);
                                $('#dataConfirmModal').modal({show:true});
                                return false;
                        });
                $('#lampiran').hide();
                $('#penanggungjawab').hide();
                $('#kat_cuti').change(function(){
                var kat_cuti=$('#kat_cuti').val();
                if(kat_cuti!=1){
                    $('#penanggungjawab').hide();
                    $('#lampiran').show();
                    return false;
                }else{
                     $('#penanggungjawab').show();
                     $('#lampiran').hide();
                } 
            });
            jQuery(function(){
                    jQuery("#kat_cuti").validate({
                            expression: "if (VAL != 0 && VAL) return true; else return false;",
                            message: "Pilih kategori cuti"
                        });
                    jQuery("#tgl_awal").validate({
                        expression: "if (VAL.length == 10 && VAL) return true; else return false;",
                        message: "Tanggal awal cuti harus diisi"
                    });
                    jQuery("#tgl_akhir").validate({
                        expression: "if (VAL.length == 10 && VAL) return true; else return false;",
                        message: "Tanggal akhir cuti harus diisi",
                    });
                    jQuery("#nip_pengganti").validate({
                        expression: "if ((jQuery('#kat_cuti').val()==1) && VAL == 0 && VAL) return false; else return true;",
                        message: "NIP Pengganti harus diisi",
                    });
                    jQuery("#almt_cuti").validate({
                        expression: "if (VAL) return true; else return false;",
                        message: "Alamat selama cuti wajib diisi"
                    });
                    jQuery("#catatan_pengaju").validate({
                        expression: "if (VAL) return true; else return false;",
                        message: "Catatan pengajuan harus diisi"
                    });
                                    jQuery('.AdvancedForm').validated(function(){
                                            alert("Use this call to make AJAX submissions.");
                                    });
            });
});        
</script>
<?php include_once 'z_footer.php';?> 